package com.hqyj.controller;


import com.hqyj.pojo.TbCar;
import com.hqyj.service.TbCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 车辆表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-car")
public class TbCarController {

    @Autowired
    private TbCarService carService;

    /**
     * 业主新增一个车辆
     * 127.0.0.1:8080/tb-car/insertCar ---- post
     * {"ownerId":"1","color":"红色","carNumber":"渝C123456","remark":"阳桑的新车"}
     * @param tbCar
     * @return
     */
    @PostMapping(value = "/insertCar",consumes = "application/json")
    public HashMap<String, Object> insertCar(@RequestBody TbCar tbCar){
        return carService.insertCar(tbCar);
    }

    /**
     * 业主修改一个车辆
     * 127.0.0.1:8080/tb-car/updateCar ---- put
     * {"id":"1","ownerId":"1","color":"红色","carNumber":"渝C123456","remark":"奥迪A6"}
     * @param tbCar
     * @return
     */
    @PutMapping(value = "/updateCar",consumes = "application/json")
    public HashMap<String, Object> updateCar(@RequestBody TbCar tbCar){
        return carService.updateCar(tbCar);
    }


    /**
     * 业主删除一个车辆
     * 127.0.0.1:8080/tb-car/deleteCar/{id} ---- delete
     * @param id
     * @return
     */
    @DeleteMapping(value = "/deleteCar/{id}")
    public HashMap<String, Object> deleteCar(@PathVariable Integer id){
        return carService.deleteCar(id);
    }

    /**
     * 业主查询自己的所有车
     * 127.0.0.1:8080/tb-car/cars/{ownerId}----get
     * @return
     */
    @GetMapping(value = "/cars/{ownerId}")
    public List<TbCar> listCarByOwnerId(@PathVariable Integer ownerId){
        return carService.listCarByOwnerId(ownerId);
    }


    /**
     * 管理员查询所有业主的所有车
     * 127.0.0.1:8080/tb-car/cars----get
     * @return
     */
    @GetMapping(value = "/cars")
    public List<TbCar> listCar(){
        return carService.listCar();
    }





}

